jQuery(function($) {
	var doc = document,
		$doc = $(doc);
	//显示表单框
	$doc.on("click", "button", function() {
		$(".pop").fadeIn();
	});
	//显示表单框
	$doc.on("click", ".clear", function() {
		$(".pop").fadeOut();
	});

	/*表单验证 -start-*/
	var need = {
		name: false,
		area: false,
		phone: false,
		qq: false,
		period: false,
		desc: false
	};

	function sendErrMessage(node, msg) {
		utils.errorMessage(node, msg || "*");
	}
	function clearErrMessage(input, node) {
		$(doc).on("focus", input, function() {
			utils.clearErrMessage(node);
		});
	}
	function empty(val, key, err, msg) {
		if (!utils.empty(val)) {
			need[key] = true;
		} else {
			need[key] = false;
			sendErrMessage(err, msg);
		}
	}
	function checkPeriod(period) {
		if (!utils.empty(period)) {
			need.period = true;
		} else {
			need.period = false;
			sendErrMessage($(".period_error"));
			return;
		}

		if (utils.isNumber(period)) {
			need.period = true;
		} else {
			need.period = false;
			sendErrMessage($(".period_error"), "必须是数值！");
		}
	}
	//提交表单
	function submitForm() {
		var realName = $(".real_name input").val(),
			area = $(".area input").val(),
			phone = $(".phone input").val(),
			qq = $(".qq input").val(),
			period = $(".period input").val(),
			desc = $(".desc textarea").val();


		empty(realName, "name", $(".name_error"));
		empty(area, "area", $(".area_error"));
		empty(phone, "phone", $(".phone_error"));
		empty(qq, "qq", $(".qq_error"));
		empty(desc, "desc", $(".desc_error"));
		// empty(period, "period", $(".period_error"));
		checkPeriod(period);

	if (need.name &&
		need.area &&
		need.area &&
		need.phone &&
		need.qq &&
		need.period &&
		need.desc) {
		//do something
		console.log(1111);
	}
	};

	$doc.on("click", ".pop button", function() {
		submitForm();
	});
	//提交表单 -end-

	//清除错误信息
	clearErrMessage(".real_name", $(".name_error"));
	clearErrMessage(".area input", $(".area_error"));
	clearErrMessage(".phone input", $(".phone_error"));
	clearErrMessage(".qq input", $(".qq_error"));
	clearErrMessage(".period input", $(".period_error"));
	clearErrMessage(".desc textarea", $(".desc_error"));
	/*表单验证 -end-*/
});